package top.lshaci.learning;

import lombok.extern.slf4j.Slf4j;

/**
 * ArrayTest
 *
 * @author lshaci
 * @since 1.0.0
 */
@Slf4j
public class ArrayTest {

    public static void main(String[] args) {
        int[] arr = {1, 8, 6, 2, 5, 4, 8, 3, 7};
//        int[] arr = {4, 3, 2, 1, 4};
        int head, tail, max = 0;
        int j = arr.length - 1;
        for (int i = 0; i < j;) {
            head = arr[i];
            tail = arr[j];
            int min = Math.min(head, tail);
            max = Math.max(max, (j - i) * min);
            log.debug("({} - {}) * {} = {}", j, i, min, (j - i) * min);
            if (head >= tail) {
                j--;
            } else {
                i++;
            }
        }

        System.err.println(max);
    }
}
